package com.yuncheng.oaApi.controller;

import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.entity.OaSysRole;
import com.yuncheng.entity.YcSysUser;
import com.yuncheng.oaApi.mapper.OaYcSysUserMapper;
import com.yuncheng.oaApi.service.IOaSysRoleService;
import com.yuncheng.oaApi.service.IOaYcSysUserService;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.common.query.QueryBuilder;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.oaApi.entity.OaQxjpz;
import com.yuncheng.oaApi.service.IOaQxjpzService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import com.yuncheng.system.api.SystemAPI;
import org.springframework.context.annotation.Lazy;

/**
 * @Description: oa_qxjpz
 * @Author: yuncheng
 * @Date: 2023-09-16
 * @Version: V1.0
 */
@Api(tags = "年休假配置接口")
@RestController
@RequestMapping("/api/spzx-oa/oaQxjpz")
public class OaQxjpzController extends BaseController<OaQxjpz, IOaQxjpzService> {

    private static final Logger log = LoggerFactory.getLogger(OaQxjpzController.class);

    @Resource
    private IOaQxjpzService oaQxjpzService;

    @Resource
    @Lazy
    private SystemAPI systemAPI;

    @Resource
    @Lazy
    private IOaYcSysUserService sysUserService;

    @Resource
    @Lazy
    private OaYcSysUserMapper oaYcSysUserMapper;

    @Resource
    @Lazy
    private IOaSysRoleService sysRoleService;

    /**
     * 分页列表查询
     *
     * @param oaQxjpz
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "年休假配置-分页列表查询")
    @ApiOperation(value = "年休假配置-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(OaQxjpz oaQxjpz, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        QueryWrapper<OaQxjpz> queryWrapper = QueryBuilder.initQueryWrapper(oaQxjpz, req.getParameterMap());
        Page<OaQxjpz> page = new Page<>(pageNo, pageSize);
        IPage<OaQxjpz> pageList = oaQxjpzService.page(page, queryWrapper);
        for (OaQxjpz vo : pageList.getRecords()) {
            formatValue(vo);
        }
        return HttpResult.ok(pageList);
    }

    @AutoLog(value = "用户列表-分页列表查询")
    @ApiOperation(value = "用户列表-分页列表查询")
    @GetMapping(value = "/userlist")
    public HttpResult<?> queryPageuserList( @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,String zxzyid,String realname) {
        if (StringUtils.isBlank(zxzyid)){
            List<OaSysRole> list = sysRoleService.list(new LambdaQueryWrapper<OaSysRole>()
                    .eq(OaSysRole::getRoleName, OaCommonFlowConstant.ROLE_NAME_ZXZY));
            OaSysRole oaSysRoles = list.get(0);
            zxzyid= oaSysRoles.getId();
        }
        Page<YcSysUser> page = new Page<>(pageNo, pageSize);

        IPage<YcSysUser> pageList = oaYcSysUserMapper.getZxzys(page, zxzyid,realname);
        return HttpResult.ok(pageList);
    }



//    /**
//     * 添加
//     *
//     * @param oaQxjpz
//     * @return
//     */
//    @AutoLog(value = "请休假配置-添加")
//    @ApiOperation(value = "oa_qxjpz-添加")
//    //@RequiresPermissions("qxjpz:OaQxjpz:add")
//    @PostMapping(value = "/add")
//    public HttpResult<?> add(@RequestBody OaQxjpz oaQxjpz) {
//        HttpResult<String> result = new HttpResult(true);
//        oaQxjpzService.save(oaQxjpz);
//        result.setResult(oaQxjpz.getId());
//        result.setMessage(I18nUtil.message("save.success"));
//        return result;
//    }

//    /**
//     * 编辑
//     *
//     * @param oaQxjpz
//     * @return
//     */
//    @AutoLog(value = "oa_qxjpz-编辑")
//    @ApiOperation(value = "oa_qxjpz-编辑")
//    //@RequiresPermissions("qxjpz:OaQxjpz:edit")
//    @PutMapping(value = "/edit")
//    public HttpResult<?> edit(@RequestBody OaQxjpz oaQxjpz) {
//        oaQxjpzService.updateById(oaQxjpz);
//        return HttpResult.ok(I18nUtil.message("update.success"));
//    }

//    /**
//     * 通过id删除
//     *
//     * @param id
//     * @return
//     */
//    @AutoLog(value = "oa_qxjpz-通过id删除")
//    @ApiOperation(value = "oa_qxjpz-通过id删除")
//    //@RequiresPermissions("qxjpz:OaQxjpz:delete")
//    @DeleteMapping(value = "/delete")
//    public HttpResult<?> delete(@RequestParam("id") String id) {
//        oaQxjpzService.removeById(id);
//        return HttpResult.ok(I18nUtil.message("delete.success"));
//    }
//
//    /**
//     * 通过id批量删除
//     *
//     * @param ids
//     * @return
//     */
//    @AutoLog(value = "oa_qxjpz-批量删除")
//    @ApiOperation(value = "oa_qxjpz-批量删除")
//    //@RequiresPermissions("qxjpz:OaQxjpz:delete")
//    @DeleteMapping(value = "/deleteBatch")
//    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
//        oaQxjpzService.removeByIds(Arrays.asList(ids.split(",")));
//        return HttpResult.ok(I18nUtil.message("delete.success"));
//    }

//    /**
//     * 通过id查询
//     *
//     * @param id
//     * @return
//     */
//    @AutoLog(value = "oa_qxjpz-通过id查询")
//    @ApiOperation(value = "oa_qxjpz-通过id查询")
//    @GetMapping(value = "/queryById")
//    public HttpResult<?> queryById(@RequestParam("id") String id) {
//        OaQxjpz oaQxjpz = oaQxjpzService.getById(id);
//        return HttpResult.ok(oaQxjpz);
//    }

    /**
     * 数据转换
     *
     * @param oaQxjpz
     */
    private void formatValue(OaQxjpz oaQxjpz) {
    }


}
